package com.bykj.taketurns.myfragment.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bykj.taketurns.R;
import com.bykj.taketurns.activity.BaseActivity;
import com.bykj.taketurns.login.LoginFirstActivity;
import com.bykj.taketurns.utils.CacheDataManager;

/**
 * 类功能
 * Zhulei---
 * 2017/7/16
 */


public class SettingMyActivity extends BaseActivity {

    private RelativeLayout btn_feedback_setting;
    private RelativeLayout btn_grade_setting;
    private RelativeLayout btn_cache_setting;
    private RelativeLayout btn_intimacy_setting;
    private RelativeLayout btn_notice_setting;
    private TextView tv_cache_data;
    private Handler handler = new Handler() {

        public void handleMessage(android.os.Message msg) {

            switch (msg.what) {

                case 0:

                    Toast.makeText(SettingMyActivity.this, "清理完成", Toast.LENGTH_SHORT).show();

                    try {

                        tv_cache_data.setText(CacheDataManager.getTotalCacheSize(SettingMyActivity.this));

                    } catch (Exception e) {

                        e.printStackTrace();

                    }

            }

        }

    };
    @Override
    public void onClick(View view) {

        switch (view.getId()) {

            case R.id.btn_feedback_setting:
                startActivity(new Intent(this, FeedBackActivity.class));
                break;
            case R.id.btn_grade_setting:
                break;
            case R.id.btn_cache_setting://清除缓存
                new Thread(new clearCache()).start();
                break;
            case R.id.btn_intimacy_setting:
                break;
            case R.id.btn_notice_setting:
                break;
            case R.id.btn_logout_setting:
                startActivity(new Intent(this, LoginFirstActivity.class));
                finish();
                break;

        }

    }

    @Override
    public void initView(Bundle savedInstanceState) {
        inittHeaderWidget();
        findViewById(R.id.tv_cache_data).setOnClickListener(this);
        findViewById(R.id.btn_feedback_setting).setOnClickListener(this);
        findViewById(R.id.btn_grade_setting).setOnClickListener(this);
        findViewById(R.id.btn_cache_setting).setOnClickListener(this);
        findViewById(R.id.btn_intimacy_setting).setOnClickListener(this);
        findViewById(R.id.btn_notice_setting).setOnClickListener(this);
        findViewById(R.id.btn_logout_setting).setOnClickListener(this);

        try {
            //缓存大小
            tv_cache_data.setText(CacheDataManager.getTotalCacheSize(this));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void initData(Bundle savedInstanceState) {
        setTitle("设置");
        BtnLeftListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                finish();

            }
        });

    }

    class clearCache implements Runnable {

        @Override

        public void run() {

            try {

                CacheDataManager.clearAllCache(SettingMyActivity.this);

                Thread.sleep(3000);
                if (CacheDataManager.getTotalCacheSize(SettingMyActivity.this).startsWith("0")) {
                    handler.sendEmptyMessage(0);
                }
            } catch (Exception e) {
                return;
            }
        }
    }

    @Override
    public int getParentView() {
        return R.layout.activity_setting_my;
    }

    @Override
    public void initToolBar() {

    }

    @Override
    protected void postData() {

    }


}
